import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../index.dart';

class ThirdPartyLoginBtns extends GetView<LoginController> {
  final VoidCallback? onWechatLogin;
  final VoidCallback? onAppleLogin;
  final bool showWechat;

  const ThirdPartyLoginBtns({
    Key? key,
    this.onWechatLogin,
    this.onAppleLogin,
    this.showWechat = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [];
    if (showWechat) {
      children.add(
        _buildLoginBtn(
          image: 'assets/images/login_wechat.png',
          onPressed: onWechatLogin,
        ),
      );
    }
    if (Platform.isIOS || Platform.isMacOS) {
      if (showWechat) {
        children.add(const SizedBox(width: 20));
      }
      children.add(
        _buildLoginBtn(
          image: 'assets/images/login_apple.png',
          onPressed: onAppleLogin,
        ),
      );
    }
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: children,
    );
  }

  Widget _buildLoginBtn({
    required String image,
    VoidCallback? onPressed,
  }) {
    return GestureDetector(
      onTap: onPressed,
      child: Image.asset(
        image,
        width: 44,
        height: 44,
      ),
    );
  }
}
